/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.chl.url;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author 陈宏亮
 */
public class UrlJoin {

    public static void main(String[] args) {
        try {
            URI url1 = new URI("http://www.bsw.com.cn/abc/");
            URI url2 = new URI("/#/abc/ddd");
            System.out.println(url1.resolve(url2));
            System.out.println(url1.resolve("/#/abc/ddd"));
        } catch (URISyntaxException ex) {
            Logger.getLogger(UrlJoin.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        testUriNormalize();
    }

    /**
     * normalize 规范uri路径，移除无意义字符。
     */
    public static void testUriNormalize() {
        try {
            URI url1 = new URI("abc//ddd////");
            URI url2 = new URI("/abc//ddd/");
            System.out.println(url1.normalize());
            System.out.println(url2.normalize());
        } catch (URISyntaxException ex) {
            Logger.getLogger(UrlJoin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
